<template>
  <border-box title="任务附件">
    <j-upload :return-url="false" v-model="fileList" @change="attachChange"></j-upload>
  </border-box>
</template>

<script>
  //附件
  import BorderBox from "./BorderBox";
  import {getAction, postAction} from "@/api/manage";

  export default {
    name: "TaskAttach",
    components: {BorderBox},
    props: ['params'],
    data() {
      return {
        fileList: []
      }
    },
    created() {
      this.queryAttchList();
    },
    methods: {
      queryAttchList() {
        getAction('task/taskInfo/queryTaskAttach', this.params).then(res => {
          if (res.success) {
            if (res.result) {
              this.fileList = res.result.map(item => {
                return {
                  fileName: item.name,
                  filePath: item.url
                }
              });
            }
          }
        })
      },
      attachChange(fileList) {
        const attachList = fileList.map(item => {
          return {
            name: item.fileName,
            url: item.filePath
          };
        });
        postAction('task/taskInfo/updateTaskAttach', {taskNo: this.params.taskNo, attachList}).then(res => {
          if (res.success) {

          } else {
            this.$message.error(res.message);
          }
        })
      }
    }
  }
</script>

<style scoped>

</style>